<template>
  <div class="category">
    <!-- 搜索框 -->
    <div class="search-bar">
      <div class="search-box" @click="toSearchPage">
        <img src="../../static/images/icon/search.png" alt="" class="search-img">
        <span class="sear-input">搜索你想要的商品</span>
      </div>
    </div>
    <div class="main">
      <div class="leftmenu">
        <ul>
          <li  v-for="(item, index) in categoryList"  :key="item.categoryId"  @click="changeIndex(index)"  :class="index == ind ? 'active' : ''"  class="menuitem">
            {{ item.categoryName }}
          </li>
        </ul>
      </div>
      <div class="rightcontent">
        <!-- 右侧上部大图 -->
        <div class="adver-map">
          <div class="item-a">
            <image :src="categoryList[ind].pic" alt="" style="height: 62px;">
          </div>
        </div>
        <!-- 右侧商品数据 -->
        <div class="cont-item">
          <div class='show-item' v-for="item in rightList" :key="item.shopId" @click='goDetail(item)'>
              <div class="more-prod-pic">
                 <img :src="item.pic" alt="" class="more-pic">
              </div>
              <div class="prod-text-right">
                <p class="prod-text more">{{item.prodName}}</p>
                <p class="cate-prod-info">{{item.brief}}</p>
                <p class="prod-price more">
                  <span style="font-size: 24rpx;">￥</span>
                  <span style="font-size: 32rpx;">{{item.price}}</span>
                  <span  style="font-size: 24rpx;">.00</span>
                </p>
              </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style>
.category{
  display: flex;
  flex-direction: row;
  height: 100%;
}
.search-bar{
    width: 100%;
    position: fixed;
    top: 0;
    left: 0;
    color: #777;
    background: #fff;
    box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.07);
    z-index: 3;
    padding: 20rpx 0;
}
.search-bar .search-box {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 60rpx;
  background: #f7f7f7;
  z-index: 999;
  width: 92%;
  border-radius: 50rpx;
  text-align: center;
  margin: auto;
}
.sear-input {
  font-size: 28rpx;
}
.main {
  position: fixed;
  display: flex;
  overflow: hidden;
  margin-top: 100rpx;
  height: 100%;
}
.search-bar .search-box .search-img {
  width: 32rpx;
  height: 32rpx;
  margin-right: 10rpx;
}
.leftmenu {
  width: 200rpx;
  height: 100%;
  box-sizing: border-box;
  background-color: #f5f6f7;
  overflow: scroll;
  z-index: 2;
}
.menuitem {
  line-height: 100rpx;
  height: 100rpx;
  text-align: center;
  border-bottom: 4rpx silid #e3e3e3;
  position: relative;
  color: #777;
  font-size: 28rpx;
}
.menuitem.active {
  color: #eb2444;
  font-size: 28rpx;
  font-weight: bold;
  position: relative;
  background: #fff;
}
.menuitem.active:before {
  position: absolute;
  left: 0;
  content: "";
  width: 8rpx;
  height: 32rpx;
  top: 29rpx;
  background: #eb2444;
  background-image: initial;
  background-position-x: initial;
  background-position-y: initial;
  background-size: initial;
  background-attachment: initial;
  background-origin: initial;
  background-clip: initial;
  background-color: rgb(235, 36, 68);
}
.rightcontent {
  width: 550rpx;
  height: 100%;
  box-sizing: border-box;
  background-color: #fff;
  z-index: 1;
  display: flex;
  flex-direction: column;
}
.rightcontent .adver-map {
  width: auto;
  box-sizing: border-box;
  overflow: hidden;
  position: relative;
  margin: 30rpx 20rpx 0;
}
.rightcontent .adver-map .item-a {
  display: block;
  font-size: 0;
  width: 100%;
}
.rightcontent .adver-map .item-a image {
  max-width: 100%;
}
.rightcontent .cont-item{
  padding: 0 20rpx 20rpx 20rpx;
  flex:1;
  overflow:auto
}
.rightcontent .cont-item .show-item {
    position: relative;
    display: flex;
    justify-content: start;
    padding: 20rpx 0;
}
.rightcontent .cont-item .show-item::after {
    content: '';
    background-color: #f4f4f4;
    left: 0;
    height: 1px;
    transform-origin: 50% 100% 0;
    bottom: 0;
    position: absolute;
    display: block;
    width: 510rpx;
    padding-left: 20rpx;
}
.rightcontent .cont-item .show-item .more-prod-pic {
    text-align: center;
    width: 150rpx;
    height: 150rpx;
    line-height: 150rpx;
    font-size: 0;
}
.rightcontent .cont-item .show-item .more-prod-pic .more-pic {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8rpx;
    vertical-align: middle;
}
.rightcontent .cont-item .show-item .prod-text-right {
    margin-left: 20rpx;
    width: 75%;
}
.rightcontent .cont-item .show-item .prod-text-right .prod-text.more {
    margin: 0;
    font-size: 28rpx;
    display: -webkit-box;
    /* 文本超出长度换行 */
    word-break: break-all;
    overflow: hidden;
    /* 文本溢出隐藏 */
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    color: #000;
}
.rightcontent .cont-item .show-item .prod-text-right .cate-prod-info {
    font-size: 22rpx;
    color: #999;
    margin: 10rpx 0 20rpx 0;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 1;
    overflow: hidden;
}
.rightcontent .cont-item .show-item .prod-text-right .prod-price.more {
    font-size: 28rpx;
    color: #eb2444;
    font-family: arial;
}
</style>
<script>
import { mapActions, mapState } from 'vuex'
export default {
  data () {
    return {
      categoryId:''
    }
  },
  computed: {
    ...mapState('category',['categoryList','ind','rightList'])
  },
  mounted () {
    this.categoryClassify()
  },
  methods: {
    ...mapActions('category',['categoryClassify','changeInd','categoryItem']),
    // 点击搜索跳转页面
    toSearchPage: function () {
      wx.navigateTo({
        url: "/pages/search-page/index",
      });
    },
    // 点击切换下标
    changeIndex(index){
      this.changeInd(index);
      this.categoryItem(this.categoryList[index].categoryId)
    },
    // 点击跳详情
    goDetail(item){
      console.log(item.prodId);
      wx.navigateTo({
        url: `/pages/prod/prod?detailsId=${item.prodId}`,
      });
    }  
  }
};
</script>


